package com.gsoc.spreadsheet.client;

/**
 * The aggregate view of all the CellClusters currently being viewed.
 * This object is what is directly represented in the UI.
 */
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.ScrollPanel;

public class Aggregate {

	/**
	 * 
	 */
	private CellCluster[][] grids;
	private FlexTable table;
	private ScrollPanel display;
	
	public Aggregate() {
		int size = CellCluster.size;
		grids = new CellCluster[size][size];
		
		table = new FlexTable();
		table.setCellPadding(0);
		table.setCellSpacing(0);
		
		for(int r = 0; r < size; ++r) {
			for(int c = 0; c < size; ++c) {
				grids[r][c] = new CellCluster(r, c);
				table.setWidget(r, c, grids[r][c].view());
			}
 		}
//		
//		initDisplay();
		
		display = new ScrollPanel(table);
		display.setAlwaysShowScrollBars(true);
	}
	
//	public void initDisplay() {
//		int size = CellCluster.size;
//		table = new FlexTable();
//		
//		table.setCellPadding(0);
//		table.setCellSpacing(0);
//		
//		Button bu = new Button("$");
//		bu.addStyleName("select-button");
//		table.setWidget(0, 0, bu);
//		
////		HorizontalPanel hor = new HorizontalPanel();
//		for(int c = 1; c <= size*size; ++c) {
////			hor.add(new Button(c + ""));
//			table.setWidget(0, c, new Button(c + ""));
//		}
////		table.setWidget(0, 1, hor);
//		
////		VerticalPanel ver = new VerticalPanel();
//		for(int r = 1; r <= size*size; ++r) {
////			ver.add(new Button(r + ""));
//			table.setWidget(r, 0, new Button(r + ""));
//		}
////		table.setWidget(1, 0, ver);
//		
//		for(int r = 1; r <= size; ++r) {
//			for(int c = 1; c <= size; ++c) {
//				grids[r-1][c-1] = new CellCluster(r, c);
//				table.setWidget(r, c, grids[r-1][c-1].view());
//			}
//		}
//	}
//	public Aggregate(int size) {
//		grids = new CellCluster[size][size];
//		
//		table = new FlexTable(size, size);
//		table.setCellPadding(0);
//		table.setCellSpacing(0);
//		
//		for(int r = 0; r < size; ++r) {
//			for(int c = 0; c < size; ++c) {
//				grids[r][c] = new CellCluster(r, c);
//				table.setWidget(r, c, grids[r][c].view());
//			}
// 		}
//		
//		display = new ScrollPanel(display);
//		display.setAlwaysShowScrollBars(true);
//	}
	
	public ScrollPanel view() {
		return display;
	}
	
	public void loadRow(int shift) {
		
	}
	
	public void loadCol(int shift) {
		
	}
}
